package com.demo.websocket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.demo.websocket.domain.DoctorInfo;
import com.demo.websocket.mapper.DoctorInfoMapper;
import com.demo.websocket.service.DoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class DocterServiceImpl implements DoctorService {

    @Autowired
    private DoctorInfoMapper doctorInfoMapper;
    @Override
    public List<DoctorInfo> findDoctorsByDepartment(Long departmentId, List<String> conditions) {
        //1.查找属于该科室的医生
        QueryWrapper<DoctorInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("dept_id", departmentId);
        List<DoctorInfo> doctorInfos = doctorInfoMapper.selectList(queryWrapper);
        //2.根据疾病匹配医生
        ArrayList<DoctorInfo> doctorInfoArrayList = new ArrayList<>();
        for (DoctorInfo doctorInfo : doctorInfos) {
            String[] split = doctorInfo.getSpecialty().split(",");
            for (String s : split) {
                if (conditions.contains(s)) {
                    doctorInfoArrayList.add(doctorInfo);
                }
            }
        }
        //后面还可以根据医生效率和其评价来排序

        return doctorInfoArrayList;
    }
}
